﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using TripleClasses;

class EGNEXtractor
{
    public static List<Triple> ExtractTriplesFromText(string text)
    {
        string pattern = @"\(\s?\d+\s?,\s?\d+\s?,\s?\d+\s?\)";
        MatchCollection allMatches = Regex.Matches(text, pattern);
        List<Triple> allTriples = new List<Triple>();
        foreach (Match tripleString in allMatches)
        {
            string[] tripleNumbers = tripleString.Value.Split(new string[] { "(", ")", ",", " " }, StringSplitOptions.RemoveEmptyEntries);
            int a, b, c;
            try
            {
                a = int.Parse(tripleNumbers[0]);
                b = int.Parse(tripleNumbers[1]);
                c = int.Parse(tripleNumbers[2]);
                allTriples.Add(new Triple(a, b, c));
            }
            catch (OverflowException)
            {
                continue;
            }
        }
        return allTriples;
    }
}
